home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 105_01.zip / SCOPE.C < prev    next >
Text File  |  1993-06-09  |  9KB  |  383 lines

  1. /*The SCOPE function is a full screen processor designed for a terminal with
  2. a 24 x 80 capability. It currently runs on a SOROK 120 or 140 but can be 
  3. adapted to run on other terminals such as TELEVIDEO and/or also changed to 
  4. allow for different control characters. The general purpose of SCOPE is
  5. twofold. It has one mode where it will allow n screenfulls of data to be 
  6. manipulated (n is controlled by parameter size) and this data may be 
  7. modified in typical full screen editor format. A delete and insert character,
  8. delete and insert line, pick and put a line, and goto first or last page
  9. capability is provided. Also an erase back one character is provided. The
  10. up and down arrows as well as the carriage return may be used to control
  11. scrolling. (up scrolling is nice but unfortunately down scrolling is not)
  12. The left and right arrows will rotate on a single line.  There is built in 
  13. error checks to prevent the arrows from going off either the beginning or
  14. end of the data.  Also notice that there are no nulls on the scope, blanks
  15. are used so that the arrows may be positioned at will without affecting the 
  16. display. To return to the calling function you must do one of three special
  17. sequences (RETURN1,RETURN2,RETURN3). Which sequence is chosen is returned to
  18. the calling function. Option is set to zero.
  19.    A second option of SCOPE is a read-only mode so that SCOPE may be used to
  20. display lists from which a choice is to be made.  In this mode only the curser
  21. control keys are active and any other key will be ignored. The SCOPE program 
  22. returns the character position to which the curser is last set so that the 
  23. procedure is merely to set the curser to the line of interest and return to
  24. the calling program. Option is set to non-zero.
  25.    The other two parameters are crtbuf, an array large enough to hold all
  26. of the characters of interest. e.g. if a 2-screenful system is applied then
  27. array should be at least 3840 characters and size should be set to 3840.
  28.    Notice that SCOPE is completely controlled by function 6 of CPM or MPM.
  29. (It has different code for each OS) and therefore any character is legal.
  30. An abort is recognized but it merely returns a -1 to the calling function
  31. and must be dealt with there.
  32. */
  33.  
  34. #define NOROLL bdos(6,033);bdos(6,'&');
  35. #define ROLL bdos(6,033);bdos(6,047);
  36. #define CLRSCOPE bdos(6,033);bdos(6,'*');
  37. #define BLANK 32
  38. #define HOME 30
  39. #define UP 11
  40. #define DOWN 10         
  41. #define FORWARD 12
  42. #define BACK 8
  43. #define CR 13
  44. #define FIRST 17
  45. #define LAST 1
  46. #define OPEN 23
  47. #define CLOSE 19
  48. #define PICK 5
  49. #define PUT 4
  50. #define INSERT 27
  51. #define GOBBLE 9
  52. #define RUB 127
  53. #define ABORT 3
  54. #define LOAD bdos(6,033);bdos(6,'=');
  55. #define OUT 25
  56. #define OUT1 31
  57. #define OUT2 20
  58. #define OUT3 21
  59.  
  60. scope(crtbuf,curser,size,opt)
  61. char crtbuf[];
  62. int curser;
  63. int size;
  64. int opt;
  65. {
  66.     char b;             
  67.     int c;
  68.     int first;
  69.     int insert;
  70.     char stack[21];
  71.     char pickbuf[80];
  72.  
  73.     stack[20] = call(5,0,0,12,0) > 255;
  74.     NOROLL
  75.     insert = first = 0;
  76.     setmem(pickbuf,80,' ');
  77.     stack[0] = stack[1] = 2;
  78.     outbuf(crtbuf,first,curser);
  79.     while((b = getbyte(stack)) != OUT)
  80.     {
  81.          if (b == OUT1 || b == OUT2 || b == OUT3)
  82.             break;
  83.              inbyte(stack);
  84.         switch (b)
  85.         {
  86.             case 0:   /*nothing typed*/
  87.                 continue;
  88.             case LAST:   /*last page (control A)*/
  89.                 fix(crtbuf,curser,insert);
  90.                 first = curser = size - 1920;
  91.                 outbuf(crtbuf,first,curser);
  92.                 break;
  93.             case ABORT:   /*control c (abort)*/
  94.                 CLRSCOPE
  95.                 return(-1);
  96.             case PUT:   /*put (control D)*/
  97.                 if(opt)
  98.                     continue;
  99.                 c = open1(crtbuf,curser,size);
  100.                 movmem(pickbuf,&crtbuf[c],80);
  101.                 outbuf(crtbuf,first,curser);
  102.                 break;
  103.             case PICK:   /*pick (control E)*/
  104.                 if(opt)
  105.                     continue;
  106.                 c = (curser / 80) * 80;
  107.                 movmem(&crtbuf[c],pickbuf,80);
  108.                 continue;
  109.               case BACK:    /*left arrow*/
  110.                 fix(crtbuf,curser,insert);
  111.                 if ((curser % 80) == 0)
  112.                 {
  113.                     curser += 79;
  114.                     setcurs(curser,first);
  115.                     break;
  116.                 }
  117.                 curser--;
  118.                                 bdos(6,b);
  119.                 break;
  120.             case GOBBLE:   /*gobble (tab)*/
  121.                 if(opt)
  122.                     continue;
  123.                 c = 79 - (curser % 80);  
  124.                 movmem(&crtbuf[curser+1],&crtbuf[curser],c);  
  125.                     crtbuf[curser+c] = ' ';
  126.                 liner(crtbuf,curser,c+1,first,stack);
  127.                 setcurs(curser,first);
  128.                 break;
  129.             case FORWARD:   /*right arrow*/
  130.                 fix(crtbuf,curser,insert);
  131.                 if ((++curser % 80) == 0)
  132.                 {
  133.                     curser -= 80;
  134.                     setcurs(curser,first);
  135.                     break;
  136.                 }
  137.                 bdos(6,b);
  138.                 break;
  139.                   case UP:   /*up arrow*/
  140.                 fix(crtbuf,curser,insert);
  141.                 if ((curser-=80) < 0)
  142.                 {
  143.                     curser+=80;
  144.                     continue;
  145.                 }
  146.                 if (curser < first)
  147.                 {
  148.                     first -= 80;
  149.                     outbuf(crtbuf,first,curser);
  150.                     break;
  151.                 }
  152.                 bdos(6,b);
  153.                 break;
  154.             case DOWN:   /*down arrow*/
  155.                 fix(crtbuf,curser,insert);
  156.                 curser += 80;
  157.                 if (curser >= size)
  158.                 {
  159.                     curser -= 80;
  160.                     continue;
  161.                 }
  162.                 if (curser >= (first + 1920))
  163.                 {
  164.                     first += 80;
  165.                     outline(crtbuf,first + 1840,80,first);
  166.                     setcurs(curser,first);
  167.                     break;
  168.                 }
  169.                 bdos(6,b);
  170.                 break;
  171.             case CR:   /*carriage return*/
  172.                 if(opt)
  173.                     return(curser);
  174.                 fix(crtbuf,curser,insert);
  175.                 c = curser % 80;
  176.                 curser = curser + 80 - c;
  177.                 if (curser >= size)
  178.                 {
  179.                     curser = curser -80 + c;
  180.                     continue;
  181.                 }
  182.                 if (curser >= (first + 1920))
  183.                 {
  184.                     first += 80;
  185.                     outline(crtbuf,first + 1840,80,first);
  186.                     setcurs(curser,first);
  187.                     break;
  188.                 }
  189.                 bdos(6,b);
  190.                 bdos(6,DOWN);
  191.                 break;
  192.             case FIRST:  /*first page (control Q)*/
  193.                 fix(crtbuf,curser,insert);
  194.                 first = curser = 0;
  195.                 outbuf(crtbuf,first,curser);
  196.                 break;
  197.             case CLOSE:  /*close (control S)*/
  198.                 if(opt)
  199.                     continue;
  200.                 fix(crtbuf,curser,insert);
  201.                 c = (curser / 80) * 80;
  202.                 movmem(&crtbuf[c+80],&crtbuf[c],size-c);
  203.                 setmem(&crtbuf[size-80],80,' ');
  204.                 outbuf(crtbuf,first,curser);
  205.                 break;
  206.             case OPEN:  /*open (control W)*/
  207.                 if(opt)
  208.                     continue;
  209.                 open1(crtbuf,curser,size);
  210.                 outbuf(crtbuf,first,curser);
  211.                 break;
  212.             case INSERT:  /*insert (escape) */
  213.                 if(opt)
  214.                     continue;
  215.                 if ((++insert & 1) == 0)
  216.                 {
  217.                     bdos(6,crtbuf[curser]);
  218.                     bdos(6,BACK);
  219.                 }
  220.                 break;
  221.             case HOME:  /*home*/
  222.                 fix(crtbuf,curser,insert);
  223.                 curser = first;
  224.                 setcurs(0,0);
  225.                 break;
  226.             case RUB:  /*rub (backspace)*/
  227.                 if(opt)
  228.                     continue;
  229.                 if ((curser % 80) == 0)
  230.                     continue;
  231.                 fix(crtbuf,curser,insert);
  232.                 bdos(6,BACK);
  233.                 bdos(6,BLANK);
  234.                 bdos(6,BACK);
  235.                 crtbuf[--curser] = ' ';
  236.                 break;
  237.             default:   /*printing characters*/
  238.                 if(opt || b < 32 || b > 126)
  239.                     continue;
  240.                 if(insert & 1)
  241.                 {
  242.                     if((c = curser % 80) == 79)
  243.                         continue;
  244.             movmem(&crtbuf[curser],&crtbuf[curser+1],79-c);
  245.                     crtbuf[curser] = b;
  246.                     bdos(6,b);
  247.                 liner(crtbuf,++curser,79-c,first,stack);
  248.                     setcurs(curser,first);
  249.                     break;
  250.                 }
  251.                 if (++curser >= (first + 1920))
  252.                 {
  253.                     crtbuf[--curser-1] = b;
  254.                     bdos(6,b);
  255.                     setcurs(curser,first);
  256.                     break;
  257.                  }
  258.                 crtbuf[curser-1] = b;
  259.                 bdos(6,b);
  260.                 break;
  261.         }
  262.         if(insert & 1)
  263.         {
  264.             bdos(6,60);
  265.             bdos(6,BACK);
  266.         }
  267.     }
  268. CLRSCOPE     
  269. if(opt)
  270.     return(curser);
  271. return(b);
  272. }
  273.  
  274. setcurs(curser,first)
  275. int curser;
  276. int first;
  277. {
  278.     
  279.     curser = curser - first; 
  280.     LOAD        
  281.     bdos(6,curser/80 + 32);
  282.     bdos(6,curser%80 + 32);
  283. }    
  284.  
  285. outbuf(crtbuf,first,curser)
  286. char crtbuf[];
  287. int first;
  288. int curser;
  289. {
  290.     int i;
  291.  
  292.     bdos(6,HOME);
  293.          for(i=0;i<1920;i++)
  294.         bdos(6,crtbuf[i+first]);
  295.     setcurs(curser,first);
  296. }
  297.  
  298. outline(crtbuf,spot,nbr,first)
  299. char crtbuf[];
  300. int spot;
  301. int nbr;
  302. int first;
  303. {
  304.     int i;
  305.  
  306.     ROLL
  307.     bdos(6,DOWN);
  308.     NOROLL
  309.     setcurs(spot,first);
  310.     for (i = 0; i < nbr; i++)
  311.         bdos(6,crtbuf[i + spot]);
  312. }
  313.  
  314. fix(crtbuf,curser,insert)
  315. char crtbuf[];
  316. int curser;
  317. int insert;
  318. {
  319.  
  320.     if(insert & 1)
  321.     {
  322.         bdos(6,crtbuf[curser]);
  323.         bdos(6,BACK);
  324.         }
  325. }
  326.  
  327. liner(crtbuf,spot,nbr,first,stack)
  328. char crtbuf[];
  329. int spot;
  330. int nbr;
  331. int first;
  332. char stack[];
  333. {
  334.     int i;
  335.  
  336.     setcurs(spot,first);
  337.     for (i = 0; i < nbr; i++)
  338.     {
  339.         bdos(6,crtbuf[i + spot]);
  340.         inbyte(stack);
  341.     }
  342.  
  343. }
  344.  
  345. getbyte(stack)
  346. char stack[];
  347. {
  348.     char b;
  349.     
  350.     if (stack[0] == stack[1])
  351.         return(0);
  352.     b = stack[stack[1]];
  353.     if (++stack[1] == 20)
  354.         stack[1] = 2;
  355.     return(b);
  356. }
  357.  
  358. inbyte(stack)
  359. char stack[];
  360. {
  361.     
  362.     if (stack[20])
  363.         if (bdos(6,254) == 0) 
  364.             return(0);   
  365.       if ((stack[stack[0]] = bdos(6,255)) == 0)
  366.         return(0);  
  367.     if (++stack[0] == 20)
  368.         stack[0] = 2;
  369.     return (1);
  370. }
  371.  
  372. open1(crtbuf,curser,size)
  373. char crtbuf[];
  374. int curser;
  375. int size;
  376. {
  377.     int c;
  378.     
  379.     c = (curser / 80) * 80;
  380.     movmem(&crtbuf[c],&crtbuf[c+80],size-c-80);
  381.     setmem(&crtbuf[c],80,' ');
  382.     return(c);
  383. }